package icu.qx.diagram.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import icu.qx.diagram.domain.MaterialInbound;
import icu.qx.diagram.domain.MaterialOutbound;
import icu.qx.diagram.service.IMaterialOutboundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/diagram/materialOutbound")
public class MaterialOutboundController extends BaseController {
    private final IMaterialOutboundService iMaterialOutboundService;
    @Autowired
    public MaterialOutboundController(IMaterialOutboundService iMaterialOutboundService)
    {
        this.iMaterialOutboundService=iMaterialOutboundService;
    }
    @RequiresPermissions("diagram:materialOutbound:list")
    @GetMapping("/list")
    public TableDataInfo list(MaterialOutbound materialOutbound)
    {
        startPage();
        List<MaterialOutbound> list=iMaterialOutboundService.selectMaterialOutboundList(materialOutbound);
        for(MaterialOutbound m:list){
            m.setCreatorName(SecurityUtils.getUsername());
        }
        return getDataTable(list);
    }
    /**
     * 导出领料统计
     */
    @RequiresPermissions("diagram:materialOutbound:export")
    @Log(title = "领料统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialOutbound materialOutbound) {
        List<MaterialOutbound> list = iMaterialOutboundService.selectMaterialOutboundList(materialOutbound);
        ExcelUtil<MaterialOutbound> util = new ExcelUtil<>(MaterialOutbound.class);
        util.exportExcel(response, list, "领料统计数据");
    }
}
